<script setup lang="ts">
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
import { useTokenStore } from "@/store";
import { silenceAuth } from "@/api/public";
import Routine from "@/libs/routine";
import { updateMp } from "@/utils/validate";
const tokenStore = useTokenStore();
onLaunch(() => {
  // #ifdef MP
  updateMp();
  // #endif
  if (tokenStore.token) return;
  Routine.getUserCode().then((code: any) => {
    //静默授权
    silenceAuth({ code: code }).then((res) => {
      const data = res.data;
      if (data.token.token) tokenStore.setToken(data.token.token);
      if (data.phone) {
        uni.setStorageSync("phone", data.phone);
      } else {
        uni.removeStorageSync("phone");
      }
    });
  });
});
onShow(() => {
  console.log("App Show");
});
onHide(() => {
  console.log("App Hide");
});


</script>

<style lang="scss">
@import "uview-plus/index.scss";
@import "@/static/css/index.scss";

//全局背景颜色
page {
  background: #f9f7f7;
}

.loading_class {
  text-align: center;
  font-size: 30rpx;
  color: #ccc;
}
</style>